using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace TPL.Xna.Common
{
    public class TextSprite : Sprite
    {
        private readonly StringBuilder _text;
        public SpriteFont Font { get; set; }

        public TextSprite(string text)
        {
            _text = new StringBuilder(text);
        }

        public void SetText(string text)
        {
            _text.Remove(0, _text.Length);
            _text.Append(text);
        }

        protected override void UpdateTapArea()
        {
            var v = Font.MeasureString(_text) * Scale;
            TapArea.Location = new Point((int)Position.X, (int)Position.Y);
            TapArea.Width = (int)v.X;
            TapArea.Height = (int)v.Y;
        }

        protected override void InternalDraw(GameTime gameTime, SpriteBatch spriteBatch)
        {
            spriteBatch.DrawString(Font, _text, Position, Color, Angle, Origin, Scale, Effect, ZIndex);
        }
    }
}
